package com.example.springbootwebdemo.config;

import com.example.springbootwebdemo.intercept.LoginHandlerIntercept;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置MVC
 */
@Configuration
public class WebMvcConfigure implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //配置默认的首页
        registry.addViewController("/").setViewName("login.html");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerIntercept())
                .addPathPatterns("/**")  //拦截的URL
                .excludePathPatterns("/", "/login.html", "/user/login", "/css/**", "/js/**", "/img/**")//排除拦截的URL不进行拦截
        ;
    }
}
